import { http } from '@/utils/http';
import type { LoginResult } from '@/types/auth';
import type { AnyObj } from '@/types/global';
import { useAuthStore } from '@/stores';
import { isLogin, getWxUserId, getWxOpenId } from '@/utils/auth';
const appId = import.meta.env.VITE_APP_ID;
const clientId = import.meta.env.VITE_CLIENT_ID;
const grantType = 'miniapp';

export const getWallet = () => {
	const wxUserId = getWxUserId();
	return http<AnyObj>({
		method: 'GET',
		url: `/wx/wallet/getWallet/${wxUserId}`
	});
}


export const getListBrokerageRecord = (data : AnyObj) => {
	const wxUserId = getWxUserId();
	return http<AnyObj>({
		method: 'GET',
		url: `/wx/wallet/listBrokerageRecord`,
		data: {
			...data,
			wxUserId
		}
	});
}

/**
 * 提现 
 * @param amount {number} 单位 分
 */
export const saveWithdraw = (amount : number) => {
	return http({
		method: 'POST',
		url: `/wx/wallet/withdraw`,
		data: {
			appId,
			wxUserId: getWxUserId(),
			receivableAccount: getWxOpenId(),
			amount
		}
	});
}

export const getWithdrawRecordList = (data : AnyObj) => {
	const wxUserId = getWxUserId();
	return http<AnyObj>({
		method: 'GET',
		url: `/wx/wallet/listWithdraw`,
		data: {
			...data,
			wxUserId
		}
	});
}

export const getWithdrawQrcode = () => {
	return http<AnyObj>({
		method: 'GET',
		url: `/wx/wallet/getWithdrawQrcode`
	});
}